<?php
/**
 * Activate/Deactivate Countries
 * 
 * 
 */

use Hive\Address\Country;
$xview = Xview::instance();
$checked = $xview->val('checked');
$enable = $xview->val('enable');
if(!empty($checked)) {
	$checked = json_decode($checked,true);
	if(is_array($checked)) {
		try {
			$infos = \Fox\Dao::infos(Country::className());
			$handle = $infos->handle();
			$handle->beginTransaction();
			foreach($checked as $code) {
				$handle->update($infos->tableName(),array('active' => $enable),array('code'=>$code));
			}
			$handle->commit();
			if($enable) {
				Fox\Message::Success(Msg(Hive::BUNDLE,Hive::COUNTRIES_ACTIVATED,count($checked)));
			} else {
				Fox\Message::Success(Msg(Hive::BUNDLE,Hive::COUNTRIES_DEACTIVATED,count($checked)));
			}
			
		}
		catch (\DBALException $e)
		{
			\Fox\Message::Error($e);
		}
		echo $xview->messages(true,true);
	}
}